﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.XPath;
using System.Xml;
using System.Xml.Xsl;

namespace EdiNet.Example
{
    class Program
    {
        static void Main(string[] args)
        {
            EdiStreamReaderExample();            
        }

        static void EdiStreamReaderExample()
        {
            using (EdiStreamReader rd = new EdiStreamReader(File.OpenRead(@"myedifile.edi")))
            {
                DataSegment seg = rd.ReadSegment();
                while (null != seg)
                {
                    Console.WriteLine(seg.SegId);
                    //do something with the segment
                    seg = rd.ReadSegment();
                }
            }
        }

        static void EdiStreamWriterExample()
        {
            using (EdiStreamWriter wr = new EdiStreamWriter(File.Create(@"myedifile.edi"), EdiReaderWriterSettings.DefaultX12))
            {
                DataSegment segIsa = new DataSegment("ISA");
                segIsa[5][0] = "ZZ";
                segIsa[6][0] = "SENDER";
                // ....
                DataSegment.FormatIsaSegment(segIsa);
                wr.WriteSegment(segIsa);
                //create more segments
            }
        }

        static void EdiXmlReaderExample()
        {
            using (EdiXmlReader ediXml = new EdiXmlReader(File.OpenRead(@"myedifile.edi")))
            {
                XPathDocument xPathDoc = new XPathDocument(ediXml);
                //xPathDoc.CreateNavigator()
                //.Select("....");
            }
        }

        static void XmlTransformExample()
        {
            //EdiXmlReader ediXmlReader = new EdiXmlReader(...);
            //EdiXmlWriter ediXmlWriter = new EdiXmlWriter(...);

            //XslCompiledTransform transform = new XslCompiledTransform();
            //transform.Load(...);

            //transform.Transform(ediXmlReader, ediXmlWriter);

        }
    }
}
